import collections
n=6
edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]
adjs=collections.defaultdict(list)
for x in edges: # 图的邻接表表示法,基本是模板
    adjs[x[0]].append(x[1]) # 1:{2}
    adjs[x[1]].append(x[0]) # 2:{1}
queue = collections.deque() # 固定写法
for key, value in adjs.items():
    if len(value) == 1:
        queue.append(key)
print(queue)

# BFS两个大循环
while(queue): # 固定写法
    size = len(queue)  # 固定写法
    n = n - size
    for _ in range(size):
        v = queue.popleft()
        v_adj = adjs[v].pop() # v的邻接仅一个,弹出即删除
        adjs[v_adj].remove(v) # 在v的邻接元素的邻接列表里删除v
        if len(adjs[v_adj]) == 1:
            queue.append(v_adj)
    if n == 1:
        print([queue.popleft()])
    if n == 2:
        print([queue.popleft(), queue.popleft()])

